package com.action;


import com.pojo.Chapter;
import com.service.ChapterService;
import com.vo.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin("*")
@RequestMapping("/chapter")
public class ChapterAction {

    @Autowired
    private ChapterService chapterService;

    /**
     * 查询对应科目章节
     * @param id 科目id
     * @return
     */
    @RequestMapping("/findChapter")
    public ResponseBean findChapter(Integer id){
        List<Chapter> list=chapterService.findChapter(id);
        if(list!=null){
            return new ResponseBean(200,0,list);
        }
        return new ResponseBean(500,0,"查询失败");
    }
    /**
     * 添加章节
     * @param chapter 章节
     * @return
     */
    @RequestMapping("/addChapter")
    public ResponseBean addChapter(Chapter chapter){
        boolean f = chapterService.save(chapter);
        return new ResponseBean(0,0,f);
    }
}
